package com.zty.xiaomi.server.Service.User;

import com.zty.xiaomi.server.Entity.User;
import com.zty.xiaomi.server.Mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.io.IOException;
@Transactional
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User getUserInfoByName(String name) {
        User user = userMapper.getUserInfoByName(name);
        return user;
    }

    @Override
    public User getUserInfoById(String userid) throws IOException {
        return userMapper.getUserInfoById(userid);
    }

    @Override
    public int updateUserVoteStatus(String user_name, int tribunal_id) throws IOException {
        int num = userMapper.updateUserVoteStatus(user_name,tribunal_id);
        if (num < 1) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
        return num;
    }

    @Override
    public int updateUserVoteStatusByTribunalId(int tribunal_id) throws IOException {
        int num = userMapper.updateUserVoteStatusByTribunalId(tribunal_id);
        if (num < 1) {
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }
        return num;
    }
}
